<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    /* transform: translateX(x);  定义转换，只是用 X 轴的值。 */
    .tab{
      position: relative;
      width: 500px;
      height: 20px;
      background-color: skyblue;
      border-radius: 25px;
      }
      .tab .round{
        position: absolute;
        width:20px;
        height: 20px; 
        background-color: #fff;
        border-radius: 30px ;
        margin-top: -2px;
        border:2px solid blue;
        left:0;
      }
      .tab .length{
        position: absolute;
        top:0;
        left: 0;
        height: 20px;
        background-color: pink;
      }
      h3{
        font-size: 20px;
        font-weight: 700;
      }
  </style>
</head>
<body>
  <h3>分数:<span class="grade">0</span></h3>
  <div class="tab">
    <div class="round"></div>
    <div class="length"></div>
  </div>
  <script>
    const tab=document.querySelector('.tab')
    const length=document.querySelector('.length')
    const round=document.querySelector('.round')
    const grade=document.querySelector('.grade')
    tab.addEventListener('click',function(e){
      // let x = e.pageX - this.offsetLeft
      // alert(x)
      console.log(e.x);
      if(e.x<=500){
      round.style.left=(e.x)+'px'
      length.style.width=(e.x)+'px'
      }
      const a=e.x/5>100?100:e.x/5
      grade.innerHTML = a
    })
  </script>
</body>
</html>